from typing import Any

from sqlalchemy import select, update, delete, insert

from recruit.adapter.database.gateway.resume_base import BaseResumeGateway
from recruit.adapter.database.models import ResumeAboutUs
from recruit.adapter.stubs import StubResumeAboutUsGateway
from recruit.domain.models.resume_id import ResumeId


class ResumeAboutUsGateway(BaseResumeGateway, StubResumeAboutUsGateway):
    async def create(self, **kwargs: Any) -> ResumeAboutUs:
        stmt = insert(ResumeAboutUs).values(**kwargs).returning(ResumeAboutUs)
        return await super().create(stmt)

    async def get_one(self, **kwargs: Any) -> ResumeAboutUs | None:
        stmt = select(ResumeAboutUs).filter_by(**kwargs)
        return await super().get_one(stmt)

    async def update(
            self,
            resume_id: ResumeId,
            **kwargs: Any
    ) -> ResumeAboutUs:
        stmt = update(ResumeAboutUs).values(**kwargs).where(
            ResumeAboutUs.resume_id == resume_id
        ).returning(ResumeAboutUs)
        return await super().update(stmt)

    async def check_resume(self, resume_id: ResumeId) -> bool:
        stmt = select(ResumeAboutUs).where(
            ResumeAboutUs.resume_id == resume_id
        ).exists()
        return await super().check_resume(stmt)

    async def delete(self, resume_id: ResumeId) -> None:
        stmt = delete(ResumeAboutUs).where(
            ResumeAboutUs.resume_id == resume_id
        )
        await super().delete(stmt)
